iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 15
0
自我挑戰組

成長型維運平台 - 單人新手到多人團隊都適用的工具系列 第 19

4-2.應用:透過Jenkins執行F5下線 (下)

  • 分享至 

  • xImage
  •  

上章Jenkins build 內寫了一個remote,裡面內容是python執行去呼叫F5做上下線動作
下面介紹F5 python Script
https://devcentral.f5.com/questions/add-value-in-data-group-via-rest-api

rpm -iUvh http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-10.noarch.rpm
yum -y install python-pip
pip
pip install requests

F5上需開啟icrd功能,測試是用版本11.6
https://devcentral.f5.com/questions/failed-to-use-rest-api-404s-53301

bigstart stop icrd
bigstart start icrd
tmsh show /sys service icrd

輸入python 進去demo 一下
首先帶入帳密post到login,取到token代入驗證去執行enabled動作

#python
>>> import requests, json, argparse, getpass, sys, time
>>> requests.packages.urllib3.disable_warnings()
>>> payload = {}
>>> payload['username'] = 'admin'
>>> payload['password'] = 'ABC'
>>> payload['loginProviderName'] = 'tmos'
>>> b = requests.session()
>>> b.headers.update({'Content-Type':'application/json'})
>>> b.auth = ('admin', 'ABC')
>>> b.verify = False
>>> b.post('https://172.16.1.1/mgmt/shared/authn/login', json.dumps(payload)).json()['token']['token']
u'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
>>> b.headers.update({'X-F5-Auth-Token':'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'})
>>> payload = {}
>>> payload['state'] = 'user-up'
>>> payload['session'] = 'user-enabled'
>>> b.put('https://172.16.1.1/mgmt/tm/ltm/pool/pool_test/members/~Common~123.12.123.123:80', json.dumps(payload)).json()
{u'state': u'up', u'kind': u'tm:ltm:pool:members:membersstate', u'inheritProfile': u'enabled', u'name': u'123.12.123.123:80', u'priorityGroup': 0, u'generation': 1111, u'partition': u'Common', u'ephemeral': u'false', u'fqdn': {u'autopopulate': u'disabled'}, u'rateLimit': u'disabled', u'session': u'monitor-enabled', u'dynamicRatio': 1, u'connectionLimit': 0, u'address': u'123.12.123.123', u'logging': u'disabled', u'fullPath': u'/Common/123.12.123.123:80', u'ratio': 1, u'selfLink': u'https://localhost/mgmt/tm/ltm/pool/pool_test/members/~Common~123.12.123.123:80?ver=11.6.1', u'monitor': u'default'}

http://docs.python-requests.org/zh_CN/latest/user/advanced.html


上一篇
4-1.應用:透過Jenkins執行F5下線 (上)
下一篇
1-11.監控工具之一:Zabbix API
系列文
成長型維運平台 - 單人新手到多人團隊都適用的工具27
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言